﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SimpleService.Config;

namespace SimpleService.ORM
{
    public sealed class DbConfig
    {
        private static ConfigHelper cfg = new ConfigHelper();
        public static string type = "mssql";
        
        public DbConfig()
        {

        }
        


        public static string dbType {
            get {
                cfg.fileName = type;
                cfg.Creat();
                cfg.Set("ConnectionString", "Data Source=(local);User ID=root; Password=123123123qq; Initial Catalog=ServiceSample;");
                cfg.Set("ConnectionStringFormat", "Data Source={DataSource};User ID={Id}; Password={Password}; Initial Catalog={TableName};");
                cfg.Set("DbType", "SimpleService.Database.MssqlProvider");
                cfg.Set("DataSource", "(local)");
                cfg.Set("Id", "root");
                cfg.Set("Password", "123123123qq");
                cfg.Set("TableName", "ServiceSample");
                return cfg.Get("DbType");
            }
            set { }
        }

        public static string connectionString
        {
            get
            {
                cfg.fileName = type;
                cfg.Creat();
                cfg.Set("ConnectionString", "Data Source=(local);User ID=root; Password=123123123qq; Initial Catalog=ServiceSample;");
                cfg.Set("ConnectionStringFormat", "Data Source={DataSource};User ID={Id}; Password={Password}; Initial Catalog={TableName};");
                cfg.Set("DbType", "SimpleService.Database.MssqlProvider");
                cfg.Set("DataSource", "(local)");
                cfg.Set("Id", "root");
                cfg.Set("Password", "123123123qq");
                cfg.Set("TableName", "ServiceSample");
                return cfg.Get("ConnectionString");
            }
            set { }
        }



        public static string mysql_sql
        {
            get
            {
                cfg.fileName = "mysql_sql";
                cfg.Creat();
                cfg.Set("select", " select * from `__table__` ");
                cfg.Set("where", " where `__key__` = __val__ ");
                cfg.Set("insert", " insert into `__table__` (__field__)  values (__fval__) ");
                cfg.Set("update", " update `__table__` set `__field__` = __fval__ where `__key__` = '__val__' ");
                cfg.Set("delete", " DELETE FROM `__table__` where `__table__`.`__key__` = __val__ LIMIT 1 ");
                cfg.Set("maxkey", " select max(__key__) as maxID from `__table__`  ");
                return cfg.Get("select");
            }
            set { }
        }


        public static string mssql_sql
        {
            get
            {
                cfg.fileName = "mssql_sql";
                cfg.Creat();
                cfg.Set("select", " select * from '__table__' ");
                cfg.Set("where", " where '__key__' = __val__ ");
                cfg.Set("insert", " insert into '__table__' (__field__)  values (__fval__) ");
                cfg.Set("update", " update '__table__' set '__field__' = __fval__ where '__key__' = '__val__' ");
                cfg.Set("delete", " DELETE FROM '__table__' where '__table__'.'__key__' = __val__ LIMIT 1 ");
                cfg.Set("maxkey", " select max(__key__) as maxID from '__table__'  ");
                return cfg.Get("select");
            }
            set { }
        }

    }
}
